package com.acwing.partition1;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author `RKC`
 * @date 2021/11/27 9:58
 */
public class AC9分组背包问题 {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = Integer.parseInt(s[0]), m = Integer.parseInt(s[1]);
        List<Integer> size = new ArrayList<>(n);
        List<List<Integer>> weight = new ArrayList<>(n), value = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            s = reader.readLine().split(" ");
            size.add(Integer.parseInt(s[0]));
            weight.add(new ArrayList<>());
            value.add(new ArrayList<>());
            for (int j = 0; j < size.get(i); j++) {
                s = reader.readLine().split(" ");
                weight.get(i).add(Integer.parseInt(s[0]));
                value.get(i).add(Integer.parseInt(s[1]));
            }
        }
        int ans = dynamicProgramming(weight, value, size, m);
        writer.write(ans + "\n");
        writer.flush();
    }

    private static int dynamicProgramming(List<List<Integer>> weight, List<List<Integer>> value, List<Integer> size, int m) {
        int[] dp = new int[m + 1];
        //遍历组，在每个组中选择一样物品
        for (int i = 1; i <= size.size(); i++) {
            for (int j = m; j >= 0; j--) {
                //遍历当前组里面的物品
                for (int k = 0; k < size.get(i - 1); k++) {
                    if (j < weight.get(i - 1).get(k)) continue;
                    dp[j] = Math.max(dp[j], dp[j - weight.get(i - 1).get(k)] + value.get(i - 1).get(k));
                }
            }
        }
        return dp[m];
    }
}
